﻿//*******************************************************************************
//Copyright 2015 TIIS  Webservices - Tanzania Immunization Information System
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
 //******************************************************************************
using GIIS.DataLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace GIIS.Tanzania.WCF
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "SupplementsManagement" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select SupplementsManagement.svc or SupplementsManagement.svc.cs at the Solution Explorer and start debugging.
    public class SupplementsManagement : ISupplementsManagement
    {
        public IntReturnValue RegisterSupplements(int childId, bool vita, bool mebendezol, DateTime date, int modifiedBy)
        {
            ChildSupplements cs = new ChildSupplements();
            cs.ChildId = childId;
            cs.Vita = vita;
            cs.Mebendezol = mebendezol;
            cs.Date = date;
            cs.ModifiedBy = modifiedBy;

            int inserted = GIIS.DataLayer.ChildSupplements.Insert(cs);
            IntReturnValue irv = new IntReturnValue();
            irv.id = inserted;
            return irv;
        }
        public IntReturnValue RegisterSupplementsBarcode(string barcode, bool vita, bool mebendezol, DateTime date, int modifiedBy)
        {
            GIIS.DataLayer.Child c = GIIS.DataLayer.Child.GetChildByBarcode(barcode);
            int i = -99;
            if (c != null)
            {
                ChildSupplements cs = new ChildSupplements();
                cs.ChildId = c.Id;
                cs.Vita = vita;
                cs.Mebendezol = mebendezol;
                cs.Date = date;
                cs.ModifiedBy = modifiedBy;
                cs.ModifiedOn = DateTime.Now;
                i = GIIS.DataLayer.ChildSupplements.Insert(cs);
            }
            IntReturnValue irv = new IntReturnValue();
            irv.id = i;
            return irv;
        }

        public int UpdateSupplements(bool vita, bool mebendezol, DateTime date, int modifiedBy, int id)
        {
            ChildSupplements cs = ChildSupplements.GetChildSupplementsById(id);
            cs.Vita = vita;
            cs.Mebendezol = mebendezol;
            cs.Date = date;
            cs.ModifiedBy = modifiedBy;

            int updated = GIIS.DataLayer.ChildSupplements.Update(cs);
            return updated;
        }
    }
}
